package torres.entity;

import torres.item.effect.Effect;

import java.io.Serializable;
import java.util.List;

/**
 *The class that contains all the abilities and its effects 
 * @author Torres
 *
 */
@SuppressWarnings("serial")
public class Ability implements Serializable {
	private String name;
	private int levelUnlocked;
	private List<Effect> effects;
	private List<Effect> costEffects;
	
	/**
	 * The default ability constructor that creates the Splash ability at level 1.
	 */
	public Ability() { //Default Constructor
		name = "Splash";
		levelUnlocked = 1;
	}
	/**
	 * The ability constructor that creates an ability based on the given name and levelUnlocked.
	 * @param name the name of the ability
	 * @param levelUnlocked the level in which the ability is unlocked
	 */
	public Ability (String name, int levelUnlocked) {
		this.name = name;
		this.levelUnlocked = levelUnlocked;
	}
	/**
	 * The ability constructor that creates an ability based on the given name, levelUnlocked, costEffects, effects.
	 * @param name the name of the ability
	 * @param levelUnlocked the level in which the ability is unlocked
	 * @param costEffects the costs on mana
	 * @param effects any possible side effects from the ability
	 */
	public Ability (String name, int levelUnlocked, List<Effect> costEffects, List<Effect> effects) {
		this.name = name;
		this.levelUnlocked = levelUnlocked;
		this.effects = effects;
		this.costEffects = costEffects;
	}
	/**
	 * The name of the ability.
	 * @param name the ability's name
	 */
	public void setName(String name) {
		this.name = name;
	}
	/**
	 * @return the name as string of this ability
	 */
	public String getName() {
		return name;
	}
	
	/**
	 * The level in which to unlock this ability.
	 * @param levelUnlocked an int value to denote the level to unlock.
	 */
	public void setLevelUnlocked(int levelUnlocked) {
		this.levelUnlocked = levelUnlocked;
	}
	/**
	 * @return the level as int in which unlocks this abilty
	 */
	public int getLevelUnlocked() {
		return levelUnlocked;
	}
	/**
	 * The ablity is used on the entity given.
	 * @param e the entity in which the ability is used on
	 */
	public void use(Entity e) {
		boolean safeToUse = true;
		for(Effect eff : costEffects)
			safeToUse = safeToUse && eff.canUse(e);
		
		if(safeToUse) {
			for(Effect eff : costEffects)
				eff.use(e);
			for(Effect eff : effects)
				eff.use(e);			
		}
	}
}
